package com.augurit.gis.server;

import java.io.IOException;

import com.esri.arcgis.interop.AutomationException;
import com.esri.arcgis.server.IServerContext;
import com.esri.arcgis.server.IServerObjectManager;
import com.esri.arcgis.server.ServerConnection;
import com.esri.arcgis.system.ServerInitializer;



/**
 * <p>Title: server创建context工厂类</p>
 * <p>Description: 只负责创建server工作的context,一旦使用完毕,需要自行将context释放.</p>
 * @author 范少辉
 * @date 2011-3-6
 */
public class ServerContextFactory{
	
	private ServerContextFactory() {
		
	}
	
	private static String domain = "test20100630";//域名，即安装了server的主机名
	private static String somname = "arcgismanager";//server管理员的用户名
	private static String sompassword = "arcgismanager";//server管理员的密码
	private static String serverIP="192.168.15.210";//server安装机器的IP；
	private static String m_serverName = "test";//服务名称
	private static String m_serverType = "MapServer";//服务类型
    
	/**
	/**
	 * 获得servercontext
	 * 
	 * @return IServerContext
	 * @throws AutomationException,IOException
	 */
	public static IServerContext getContext(String servername,String servertype) throws AutomationException,IOException
    {
		    IServerContext servercontext=null;
			ServerInitializer serverInitializer = new ServerInitializer();   
	  	    serverInitializer.initializeServer(domain, somname, sompassword);  
	  	    ServerConnection connection = new ServerConnection(); 
	  	    connection.connect(serverIP);
	  	    IServerObjectManager som = connection.getServerObjectManager(); 
	  	    if(servername==""||servername==null)
	  	    {
	  	    	servercontext = som.createServerContext(m_serverName,m_serverType); 
	  	    }
	  	    else
	  	    {
	  	    	 servercontext = som.createServerContext(servername,servertype); 
	  	    }
		    return servercontext;
    }

	public  String getDomain() {
		return domain;
	}

	public  void setDomain(String domain) {
		ServerContextFactory.domain = domain;
	}

	public  String getSomname() {
		return somname;
	}

	public  void setSomname(String somname) {
		ServerContextFactory.somname = somname;
	}

	public  String getSompassword() {
		return sompassword;
	}

	public  void setSompassword(String sompassword) {
		ServerContextFactory.sompassword = sompassword;
	}

	public  String getServerIP() {
		return serverIP;
	}

	public  void setServerIP(String serverIP) {
		ServerContextFactory.serverIP = serverIP;
	}
}
